<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>foreach遍历数组</title>
</head>

<body>
  <script>
    // foreach和map区别
    // 1.foreach只遍历,没有返回值
    // 2.map有返回值
    // 3.foreach更适合于遍历数组对象
    const arr = [1, 2, 3, 4]
    arr.forEach(function (item, index) {
      console.log(item, index);
    })
  </script>
</body>

</html>